/*
 * robot.h
 *
 *  Created on: 2012-10-30
 *      Author: maciek
 */

#ifndef ROBOT_H_
#define ROBOT_H_
using namespace std;

#include <list>
#include <complex>
#include <queue>
#include <fstream>
#include <ctime>
#include "state.h"
#include "signalR.h"
#include "worldMap.h"
class robot {
public:

	robot(double& AppearTime, complex<double> A, complex<double> B, complex<double> C, complex<double> D);
	virtual 		~robot();
	int 			calculateTrack( complex<double> S, complex<double> E );
	/* TODO: Dziergwa
	 * possible actions: move, stop. Should change state of robot. Robot
	 * should make appropriate action to his state!
	 */
	int				makeMove( const double Time, double SignalTTL );

	int				loadMap(int** NewMap, complex<int> MapSize);

	/*
	 * Prints out robots map. For debugging purposes only
	 */
	int				showRobotMap( void );

	/* TODO: Paweł
	 * generate signal for time. Can change state.
	*/
	signalR* 		sendSignal(double Time );

	void			receiveSignal(signalR& Signal);

	void 			updateSignal(signalR &Signal);

	void 			removeFromSignals(int Priority);
	void 			changeSignalPriority(int From, int To);

	complex<double> getCurrentPlace(void);

	int 			getPriority(void);
	void			setPriority(int Priority);

	state			getState(void);
	complex<double> getA(void);
	complex<double> getB(void);
	complex<double> getC(void);
	complex<double> getD(void);

private:
	static int		_lastRobotPriority;
	state 			_state;
	complex<double> _currentPlace; // current, precise place
	int 			_priority;
	double			_timeOfLastSignal;
	static double 	_signalPeriod;
	double			_timeOfLastAction; // or last send signal
	double			_robotV; // it have to be somewhere //??
	/* list of current  signals. When thier time goes to end they are deleted.
	 * When robot have recived new signal it is added here. We have to check
	 * if we haven't got two signals from the same robot.
	 * TODO: Dziergwa - interface to that
	 */
	list<signalR>	_currentSignals;
	/* robot must have his own map - it could be pointer to real map */

	int**						_map;
	complex<double>				_mapSize;
	complex<double>			 	_A; //Rozbilem na poszczegolne punkty, zeby bylo tak jak w mapie
	complex<double>				_B;
	complex<double>				_C;
	complex<double>				_D;
	vector< complex<double> >	_path; // fields that the robot will cross
	void 						floodFill(int x, int y, complex<int> E, int value, int** &result);
};

#endif /* ROBOT_H_ */
